using System;
using System.Collections.Generic;
using System.Text;

namespace LogParser.DA
{
    public class LogFileModel
    {

        private DA.DataObjects.LogFilesDSTableAdapters.LogFilesTableAdapter lfta;

        public LogFileModel()
        {
            lfta = TableAdapters.LogFilesTableAdapter();
        }

        public int GetLogId( string logName )
        {
            LogParser.DA.DataObjects.LogFilesDS.LogFilesRow lfr = (LogParser.DA.DataObjects.LogFilesDS.LogFilesRow) ( lfta.LogFilesSelectByName( logName ).Rows[ 0 ] );

            return lfr.LogId;
        }



        public static List<int> GetLogIdList( int leagueId )
        {

            DA.DataObjects.LogFilesDSTableAdapters.LogFilesTableAdapter ta = TableAdapters.LogFilesTableAdapter();

            LogParser.DA.DataObjects.LogFilesDS.LogFilesDataTable dt = (LogParser.DA.DataObjects.LogFilesDS.LogFilesDataTable) ( ta.LogFilesSelectByLeagueId( leagueId ) );

            List<int> returnList = new List<int>();

            foreach ( LogParser.DA.DataObjects.LogFilesDS.LogFilesRow dr in dt.Rows )
            {
                returnList.Add( dr.LogId );
            }

            return returnList;
        }

        public static LogParser.DA.DataObjects.LogFilesDS.LogFilesRow GetLog( int logId )
        {
            DA.DataObjects.LogFilesDSTableAdapters.LogFilesTableAdapter ta = TableAdapters.LogFilesTableAdapter();

            LogParser.DA.DataObjects.LogFilesDS.LogFilesRow lfr = (LogParser.DA.DataObjects.LogFilesDS.LogFilesRow) ( ta.LogFilesSelectById( logId ).Rows[ 0 ] );

            return lfr;
        }

        public static DA.DataObjects.LogFilesDS.LogFilesDataTable GetLogList()
        {

            DA.DataObjects.LogFilesDSTableAdapters.LogFilesTableAdapter ta = TableAdapters.LogFilesTableAdapter();

            
            DA.DataObjects.LogFilesDS.LogFilesDataTable dt = (LogParser.DA.DataObjects.LogFilesDS.LogFilesDataTable) ( ta.GetData() );

            return dt;
        }


        public static bool DeleteAllDataByLogId( int logId )
        {

            DA.DataObjects.LogFilesDSTableAdapters.LogFilesTableAdapter ta = TableAdapters.LogFilesTableAdapter();

            bool result = false;

            try
            {
                ta.DeleteAllLogDataByLogId( logId );
                result = true;
            } catch {
                result = false;
            }

            return result;
        }




    }
}
